#include "Button.h"

Button::Button(int x, int y,int width, int height,std::string btntext){
    _x = x;
    _y = y;
    _width = width;
    _height = height;
    _text = btntext;
}

void Button::draw(){
    UIComponent::draw();
    oslSetFont(font);
    oslDrawString(_x+5, _y+7,_text.c_str());

    if(state == 0){
        oslDrawRect(_x+1,_y+1,_x+_width-1,_y+_height-1,LITEGRAY);
    }else if(state == 1){
        oslDrawRect(_x+1,_y+1,_x+_width-1,_y+_height-1,RGB(0,255,255));
    }else if(state == 2){
        oslDrawRect(_x+1,_y+1,_x+_width-1,_y+_height-1,RGB(255,0,255));
    }
}

void Button::setDownload(std::string url,std::string name){
    _peer = new Peer(url,name);
}

void Button::onselect(){
    UIComponent::onselect();
    if(downloadable){
        _peer->run();
    }
}
